package com.yc.annotation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class InfoTracker {
	public static void main(String[] args) {
		InfoTracker tracker = new InfoTracker();
		tracker.tracker(Demo.class);
	}

	private void tracker(Class<?> cls) {
		Info info = null;

			try {
				Object obj = cls.newInstance();
				for(Method method : cls.getDeclaredMethods()) {  //循环给定类的所有方法
					if(method.isAnnotationPresent(Info.class)) {
						info = method.getAnnotation(Info.class); //判断这个方法上是否有Info注解
						System.out.println(info.id() + ":" + info.desc());//获取这个方法上的注解
						
						if(info.id() ==3) {
							System.out.println(method.invoke(obj, 1,2));
						}
					}
					
				}
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (SecurityException e) {
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}

		
	}
}
